/**
 * Project Name:YCApiServer-Api
 * File Name:InspireController.java
 * Package Name:com.yc.music.controller.Api.auth
 * Date:2016年5月12日上午11:30:58
 * Copyright (c) 2016 
 *
 */
package com.yc.music.controller.Api.auth;

import java.util.HashMap;
import java.util.Map;

import javax.validation.Valid;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.yc.music.common.context.YcContext;
import com.yc.music.model.draft.Draft;
import com.yc.music.service.service21.DraftService;

/**
 * 
 * ClassName: DraftController <br/>
 * Function: 草稿. <br/>
 * Reason: TODO ADD REASON(可选). <br/>
 * date: 2016年8月11日 下午7:42:25 <br/>
 *
 * @author qinhaiguan
 * @version
 */
@Controller
@RequestMapping("/draft")
public class DraftController {
	
	private static Logger logger = Logger.getLogger(DraftController.class);
	
	@Autowired
	private DraftService draftService;
	
	
	@ResponseBody
	@RequestMapping(value="save", method = RequestMethod.POST, produces = "application/json")
	public Map<String,Object> saveSprie(
			@Valid Draft draft,BindingResult binding) {
		
		Map<String,Object> result  = new HashMap<String,Object>();
		try {
			result=draftService.saveDraft(draft,result,binding);
		} catch (Exception e) {
			result.put(YcContext.CODE, 500);
			result.put(YcContext.MESSAGE, YcContext.SYS_ERROR_MSG);
			result.put(YcContext.DATA,YcContext.EMPTY_STRING);
			logger.error(e);
		}
		return result;
	}
	
	
	@ResponseBody
	@RequestMapping(value="list", method = RequestMethod.POST, produces = "application/json")
	public Map<String,Object> draftList(
			@RequestParam("page") Integer page,
			@RequestParam("uid") Integer uid) {
		Map<String,Object> result  = new HashMap<String,Object>();
		try {
			draftService.draftList(page, uid, result);
		} catch (Exception e) {
			result.put(YcContext.CODE, 500);
			result.put(YcContext.MESSAGE, YcContext.SYS_ERROR_MSG);
			result.put(YcContext.DATA,YcContext.EMPTY_STRING);
			logger.error(e);
		}
		return result;
	}
	
/*	@ResponseBody
	@RequestMapping(value="update", method = RequestMethod.POST, produces = "application/json")
	public Map<String,Object> updateSprize(
			@Valid Inspire spire,BindingResult binding) {
		
		Map<String,Object> result  = new HashMap<String,Object>();
		try {
			result=inspireService.updateSprie(spire, binding,result);
		} catch (Exception e) {
			result.put(YcContext.CODE, 500);
			result.put(YcContext.MESSAGE, YcContext.SYS_ERROR_MSG);
			result.put(YcContext.DATA,YcContext.EMPTY_STRING);
			logger.error(e);
		}
		return result;
	}*/
	
	@ResponseBody
	@RequestMapping(value="delete", method = RequestMethod.POST, produces = "application/json")
	public Map<String,Object> deleteSprie(
			@RequestParam("id") Integer id) {
		
		Map<String,Object> result  = new HashMap<String,Object>();
		try {
			result=draftService.deleteDraftById(id, result);
		} catch (Exception e) {
			result.put(YcContext.CODE, 500);
			result.put(YcContext.MESSAGE, YcContext.SYS_ERROR_MSG);
			result.put(YcContext.DATA,YcContext.EMPTY_STRING);
			logger.error(e);
		}
		return result;
	}

}
